home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-09-08 | 4.3 KB | 158 lines |
- package applets;
-
- import shout3d.*;
- import shout3d.core.*;
- import custom_nodes.*;
-
-
- public class MultiViewpointsGUIPanel extends Shout3DPanel implements DeviceObserver {
-
-
- int pixelStartX;
- int pixelStartY;
-
- float headingSpeed = 0.0f;
- float pitchSpeed = 0.0f;
- float distanceSpeed = 0.0f;
- float zoomPixelFactor = 0.0f;
-
- TargetViewpoint[] cameras = new TargetViewpoint [3];
- int currentCam = 1;
- int totalCams = 1;
-
-
- float initialHeading;
- float initialPitch;
- float initialDistance;
- float[] initialCenter;
- float initialFieldOfView;
-
-
-
- public MultiViewpointsGUIPanel(Shout3DApplet applet, int width, int height){
- super(applet, width, height);
- }
-
-
- public void customInitialize() {
-
- addDeviceObserver(this,"MouseInput", null);
- getRenderer().addRenderObserver(this, null);
- cameras[0] = (TargetViewpoint) getCurrentBindableNode("Viewpoint");
-
- //store initial values
- initialHeading = cameras[0].heading.getValue();
- initialPitch = cameras[0].pitch.getValue();
- initialDistance = cameras[0].distance.getValue();
- initialCenter = cameras[0].center.getValue();
- initialFieldOfView = cameras[0].fieldOfView.getValue();
-
- zoomPixelFactor = (initialDistance/10)/150;
-
-
- }
-
-
- protected void finalize() {
- removeDeviceObserver(this,"MouseInput");
- getRenderer().removeRenderObserver(this);
- }
-
-
-
- public boolean onDeviceInput(DeviceInput di, Object userData) {
-
- MouseInput mi = (MouseInput) di;
- switch (mi.which){
-
- case MouseInput.DOWN:
- pixelStartX = mi.x;
- pixelStartY = mi.y;
- return true;
-
- case MouseInput.UP:
- headingSpeed = 0.0f;
- pitchSpeed = 0.0f;
- distanceSpeed = 0.0f;
- return true;
-
- case MouseInput.DRAG:
-
- //if left button used
- if(mi.button == 0) {
-
- int pixelEndX = mi.x;
- int pixelEndY = mi.y;
-
- int dragDistanceX = pixelEndX - pixelStartX;
- int dragDistanceY = pixelEndY - pixelStartY;
-
- headingSpeed = dragDistanceX/70f;
- pitchSpeed = dragDistanceY/70f;
-
- return true;
- }
-
- //if right button used
- if(mi.button == 1) {
-
- int pixelEndY = mi.y;
- int dragDistanceY = pixelEndY - pixelStartY;
- distanceSpeed = dragDistanceY*zoomPixelFactor;
- return true;
- }
-
- }//end of switch
-
- return false;
-
- }//end of onDeviceInput()
-
-
-
- public boolean createCamera() {
-
- if (totalCams < 3) {
-
- totalCams++;
- currentCam = totalCams;
- cameras[currentCam-1] = new TargetViewpoint(this);
-
- //add to scene and bind
- Node [] kids = {cameras[currentCam-1]};
- getScene().addChildren(kids);
-
- //set to initial values
- cameras[currentCam-1].isBound.setValue(true);
- cameras[currentCam-1].heading.setValue(initialHeading);
- cameras[currentCam-1].pitch.setValue(initialPitch);
- cameras[currentCam-1].distance.setValue(initialDistance);
- cameras[currentCam-1].center.setValue(initialCenter);
- cameras[currentCam-1].fieldOfView.setValue(initialFieldOfView);
-
- return true;
- }
- return false;
- }//end of createCamera()
-
-
-
- public void onPreRender (Renderer r, Object o) {
-
- float headingDelta = headingSpeed/getFramesPerSecond();
- float temp = cameras[currentCam-1].heading.getValue() - headingDelta;
- cameras[currentCam-1].heading.setValue(temp);
-
- float pitchDelta = pitchSpeed/getFramesPerSecond();
- temp = cameras[currentCam-1].pitch.getValue() - pitchDelta;
- cameras[currentCam-1].pitch.setValue(temp);
-
- float distanceDelta = distanceSpeed/getFramesPerSecond();
- temp = cameras[currentCam-1].distance.getValue() + distanceDelta;
- cameras[currentCam-1].distance.setValue(temp);
-
- }//end of onPreRender()
-
-
- }//end of class
-